﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autorent.Desktop.Model.AutorentMngrServiceReference;
using Autorent.Desktop.Model.Services;

namespace Autorent.Desktop.Main
{
    /// <summary>
    /// System User credentials, validation and role methods
    /// </summary>
    public static class User
    {
        public static string UserName { get; set; }
        public static string Password { get; set; }

        public static void SetCredentials(string userName, string password)
        {
            UserName = userName;
            Password = password;
        }

        //Get System User role
        public static bool IsRole(string role)
        {
            ISystemUsersRepository systemUsersRepository = new SystemUsersRepository();
            if (role == systemUsersRepository.GetSystemUserByName(UserName).SystemUserRole) { return true; }
            else return false;
        }

        //Validate user at every business logic operation
        public static bool Validate(string userName, string password)
        {
            bool isValid = false;

            ISystemUsersRepository systemUsersRepository = new SystemUsersRepository();
            SystemUser systemUser = systemUsersRepository.GetSystemUserByName(userName);

            if (systemUser != null)
            {
                if (password == systemUser.SystemUserPassword) { isValid = true; }
                else isValid = false;
            }

            return isValid;
        }
    }
}
